package com.hr.lx.exception;

import com.hr.lx.config.State;
import com.hr.lx.entity.ResponseJson;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class HandleException {
    @ResponseBody
    @ExceptionHandler(BusinessException.class)
    public ResponseJson handleBusinessException(BusinessException businessException) {
        return new ResponseJson(businessException.getCode(), businessException.getMsg());
    }

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public ResponseJson handleException(Exception e) {
        return new ResponseJson(State.ERROR, "发生未知错误");
    }
}
